package patrol.mobile.com.mobilepatrol.api;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import patrol.mobile.com.mobilepatrol.utils.UIHelper;


/**
 * Created by 健 on 2014/9/7.
 */
public class MyHandler extends Handler{
    public final static int MSG_ERR=-1;
    public final static int MSG_FAILURE=0;
    public final static int MSG_SUCCESS=1;
    public final static int MSG_PAGE=2;

    private Context context;

    public MyHandler(Context context) {
        this.context = context;
    }

    @Override
    public void handleMessage(Message msg) {
        if(msg.what==MSG_SUCCESS){
            onResultSuccess(msg.obj);
        }else if(msg.what==MSG_FAILURE){
            if(msg.obj!=null)
                UIHelper.ToastMessageCenter(context,msg.obj.toString());
            onResultFailure();
        }else if(msg.what==MSG_ERR){
            AppException ae= (AppException) msg.obj;
            ae.makeToast(context);
            onResultFailure();
        }
    }

    /**
     * 请求成功 返回结果json信息
     * @param data
     */
    public void onResultSuccess(Object data){}
    public void onResultFailure(){}
}
